package common.store.admin.dao;

import common.store.admin.dto.Product;
import common.store.admin.vo.QueryVo;
import common.store.common.util.C3p0Pool;
import common.store.web.bean.Order;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;
import org.apache.commons.dbutils.handlers.BeanListHandler;

import java.sql.SQLException;
import java.util.Collections;
import java.util.List;

public class OrderDao {

    static QueryRunner qr;

    static {
        qr = new QueryRunner(C3p0Pool.getDataSource());
    }


    public List<Order> getOrderList(){
        String sql = "select * from orders";

        try {
            System.out.println(sql);
            return qr.query(sql , new BeanListHandler<>(Order.class));//数组代替了可变参数
        } catch (SQLException e) {
            e.printStackTrace();
        }

        return null;
    }

    public List<Order> getOrderByOid(String oid){
        String sql = "select * from orders where oid = ?";

        try {
            return qr.query(sql , new BeanListHandler<>(Order.class) , oid);
        } catch (SQLException e) {
            e.printStackTrace();
        }

        return null;
    }

    public Integer DelOrderByOid(String oid){

        try {
            return qr.update("delete from orders  where oid = ?" , oid);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return 0;

    }

}
